package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 插入
     *
     * @param dish 菜
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 获取计数盘名称
     *
     * @param name 名称
     * @return {@link Integer}
     */
    @Select("select count(*) from dish where name =#{name}")
    Integer getCountDishName(String name);

    /**
     * 选择列表
     *
     * @param dishQuery 菜式查询
     * @return {@link List}<{@link Dish}>
     */
    List<Dish> selectList(Dish dishQuery);

    /**
     * 按id删除批处理
     *
     * @param ids ids
     */
    void deleteBatchByIds(List<Long> ids);

    /**
     * 按id和状态选择计数
     *
     * @param ids    ids
     * @param status 状态
     * @return {@link Integer}
     */
    Integer selectCountByIdsAndStatus(List<Long> ids, Integer status);

    /**
     * 按id获取菜肴
     *
     * @param id id
     * @return {@link Dish}
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, " +
            "create_user, update_user from dish where id=#{id}")
    Dish getDishById(Long id);

    /**
     * 更新盘
     *
     * @param dish 菜
     */
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 更改状态
     *
     * @param status 状态
     */
    void changeStatus(Long id, Integer status);

    /**
     * 按id获取计数
     *
     * @param id id
     * @return {@link Integer}
     */
    Integer getCountById(Long id);

    /**
     * 按类别id查询菜盘
     *
     * @param categoryId 类别id
     * @return {@link Dish}
     */
    List<Dish> queryDishByCategoryId(Long categoryId);

    /**
     * 获取计数状态
     *
     * @param setmealDishes 套餐菜肴
     * @return {@link Integer}
     */
    Integer getCountStatus(List<SetmealDish> setmealDishes);

    /**
     * 选择菜肴风味
     *
     * @param id id
     * @return {@link List}<{@link DishFlavor}>
     */
    List<DishFlavor> selectDishFlavor(Long id);

    /**
     * 按id选择
     *
     * @param dishId 碟子id
     * @return {@link Dish}
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, " +
            "create_user, update_user from dish where id=#{dishId}")
    Dish selectById(Long dishId);
}
